<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="据点site" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="site">
              <a-input v-model="model.site" placeholder="请输入据点site"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="说明(简称)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="descriptionAbbr">
              <a-input v-model="model.descriptionAbbr" placeholder="请输入说明(简称)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="区域" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="region">
              <a-input v-model="model.region" placeholder="请输入区域"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="出货单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shipmentNo">
              <a-input v-model="model.shipmentNo" placeholder="请输入出货单号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="出货项次" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shipmentItem">
              <a-input v-model="model.shipmentItem" placeholder="请输入出货项次"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="方向" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="direction">
              <a-input v-model="model.direction" placeholder="请输入方向"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="单据扣账日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="documentDate">
              <a-input v-model="model.documentDate" placeholder="请输入单据扣账日期"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="产品编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productCode">
              <a-input v-model="model.productCode" placeholder="请输入产品编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="品名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productName">
              <a-input v-model="model.productName" placeholder="请输入品名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="规格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="specification">
              <a-input v-model="model.specification" placeholder="请输入规格"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="成本分群" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="costGroup">
              <a-input v-model="model.costGroup" placeholder="请输入成本分群"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="description1">
              <a-input v-model="model.description1" placeholder="请输入说明"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="销售分类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="salesCategory">
              <a-input v-model="model.salesCategory" placeholder="请输入销售分类"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="description2">
              <a-input v-model="model.description2" placeholder="请输入说明"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="客户编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customerCode">
              <a-input v-model="model.customerCode" placeholder="请输入客户编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="交易对象简称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customerAbbr">
              <a-input v-model="model.customerAbbr" placeholder="请输入交易对象简称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="渠道" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="channel">
              <a-input v-model="model.channel" placeholder="请输入渠道"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="成本域" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="costDomain">
              <a-input v-model="model.costDomain" placeholder="请输入成本域"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="description3">
              <a-input v-model="model.description3" placeholder="请输入说明"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="基础单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="baseUnit">
              <a-input v-model="model.baseUnit" placeholder="请输入基础单位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="客户订购单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customerPo">
              <a-input v-model="model.customerPo" placeholder="请输入客户订购单号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderNo">
              <a-input v-model="model.orderNo" placeholder="请输入订单单号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单项次" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderItem">
              <a-input v-model="model.orderItem" placeholder="请输入订单项次"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单项序" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderSequence">
              <a-input v-model="model.orderSequence" placeholder="请输入订单项序"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单分批序" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderBatch">
              <a-input v-model="model.orderBatch" placeholder="请输入订单分批序"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="销售成本科目" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="costAccount">
              <a-input v-model="model.costAccount" placeholder="请输入销售成本科目"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="description4">
              <a-input v-model="model.description4" placeholder="请输入说明"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="销售收入科目" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="revenueAccount">
              <a-input v-model="model.revenueAccount" placeholder="请输入销售收入科目"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="description5">
              <a-input v-model="model.description5" placeholder="请输入说明"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="凭证号码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="voucherNo">
              <a-input v-model="model.voucherNo" placeholder="请输入凭证号码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="凭证日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="voucherDate">
              <a-input v-model="model.voucherDate" placeholder="请输入凭证日期"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="销售数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="salesQty">
              <a-input v-model="model.salesQty" placeholder="请输入销售数量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="销货成本" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="costOfSales">
              <a-input v-model="model.costOfSales" placeholder="请输入销货成本"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="销售收入" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="salesRevenue">
              <a-input v-model="model.salesRevenue" placeholder="请输入销售收入"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="销售额占比" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="salesRatioPercent">
              <a-input v-model="model.salesRatioPercent" placeholder="请输入销售额占比"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="毛利" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="grossProfit">
              <a-input v-model="model.grossProfit" placeholder="请输入毛利"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="毛利占比" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="profitRatioPercent">
              <a-input v-model="model.profitRatioPercent" placeholder="请输入毛利占比"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="毛利率%" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="grossMarginPercent">
              <a-input v-model="model.grossMarginPercent" placeholder="请输入毛利率%"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="description6">
              <a-input v-model="model.description6" placeholder="请输入说明"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="批号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="batchNo">
              <a-input v-model="model.batchNo" placeholder="请输入批号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="人员编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="staffCode">
              <a-input v-model="model.staffCode" placeholder="请输入人员编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="业务人员名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="salesPerson">
              <a-input v-model="model.salesPerson" placeholder="请输入业务人员名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="成本金额-材料" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="materialCost">
              <a-input v-model="model.materialCost" placeholder="请输入成本金额-材料"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="成本金额-人工" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="laborCost">
              <a-input v-model="model.laborCost" placeholder="请输入成本金额-人工"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="成本金额-加工" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="processingCost">
              <a-input v-model="model.processingCost" placeholder="请输入成本金额-加工"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="销货成本-制费一" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="overheadCost1">
              <a-input v-model="model.overheadCost1" placeholder="请输入销货成本-制费一"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="销货成本-制费二" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="overheadCost2">
              <a-input v-model="model.overheadCost2" placeholder="请输入销货成本-制费二"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="销货成本-制费三" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="overheadCost3">
              <a-input v-model="model.overheadCost3" placeholder="请输入销货成本-制费三"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="年份" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="year">
              <a-input v-model="model.year" placeholder="请输入年份"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="月份" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="month">
              <a-input v-model="model.month" placeholder="请输入月份"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'Cxcq003ChDetailForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/ch/cxcq003ChDetail/add",
          edit: "/ch/cxcq003ChDetail/edit",
          queryById: "/ch/cxcq003ChDetail/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>